package com.question.business.user.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.question.business.user.entity.UserRole;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 用户角色Mapper接口
 *
 * @author star
 * @since 2023-09-13
 */
@Mapper
public interface UserRoleMapper extends BaseMapper<UserRole> {

    /**
     * 用户角色查询
     *
     * @param userId 用户ID
     * @return List<String> 响应参数
     */
    @Select("SELECT role_id FROM t_user_role WHERE user_id = #{userId}")
    List<String> queryRoleByUserId(String userId);

    /**
     * 角色用户查询
     *
     * @param roleId 角色ID
     * @return List<String> 响应参数
     */
    @Select("SELECT user_id FROM t_user_role WHERE role_id = #{roleId}")
    List<String> queryUserByRoleId(String roleId);

    /**
     * 根据用户ID删除角色
     *
     * @param userId 用户ID
     */
    @Delete("DELETE FROM t_user_role WHERE user_id = #{userId}")
    void deleteByUserId(String userId);

    /**
     * 根据用户ID删除角色
     *
     * @param roleId 用户ID
     */
    @Delete("DELETE FROM t_user_role WHERE role_id = #{roleId}")
    void deleteByRoleId(String roleId);

}